package com.lyl.goods.service.impl;

import com.lyl.goods.mapper.ProductMapper;
import com.lyl.goods.pojo.Product;
import com.lyl.goods.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;

    @Override
    public void add(String name, Integer price, Integer stock, String description) {
        productMapper.add(name, price, stock, description);
    }

    @Override
    public Product getProductById(Long id) {
        return productMapper.selectById(id);
    }

    @Override
    public void updateProduct(Product product) {

        productMapper.updateById(product);
    }

    @Override
    public void delete(Long id) {
        productMapper.delete(id);
    }


    @Override
    public List<Product> getProductList(int pageNum, int pageSize) {
        int offset = (pageNum - 1) * pageSize;
        return productMapper.getProductList(offset, pageSize);
    }

    @Override
    public int getTotalCount() {
        return productMapper.getTotalCount();
    }


    @Override
    public List<Product> getProduct(Integer productId) {
        return productMapper.getProduct(productId);
    }

    @Override
    public void batchDeleteProducts(List<Integer> selectedProductIds) {
        // 调用数据访问层进行批量删除操作
        productMapper.batchDeleteProducts(selectedProductIds);
    }

}
